package erfgame.frontend.desktop.view.main;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;

import erfgame.frontend.desktop.view.AbstractView;

public class MainView extends AbstractView {
	
	public static final int ACTION_TYPE_EXIT 			= -1;
	public static final int ACTION_TYPE_OPTIONS 		= 1;
	public static final int ACTION_TYPE_CREATE_WORLD 	= 2;
	public static final int ACTION_TYPE_START_GAME 		= 3;
	public static final int ACTION_TYPE_LOAD_GAME		= 4;

	public static final int ACTION_TYPE_VIEW_WORLD		= 10;

	private static final String RESOURCES = "bundles.MainView";
	
	private JComponent component;
	
	private JButton exitButton;
	private JButton optionsButton;
	private JButton createWorldButton;
	private JButton startGameButton;
	private JButton loadGameButton;
	private JButton viewWorldButton;
	
	public MainView() {
		
	}
	
	public void init() {
		
		ResourceBundle resources = ResourceBundle.getBundle( RESOURCES );
		
		this.component = new JPanel( new GridBagLayout() );
		
		this.exitButton = new JButton( resources.getString( "exit" ) );
		this.optionsButton = new JButton( resources.getString( "options" ) );
		this.createWorldButton = new JButton( resources.getString( "create_world" ) );
		this.startGameButton = new JButton( resources.getString( "start_game" ) );
		this.loadGameButton = new JButton( resources.getString( "load_game" ) );
		this.viewWorldButton = new JButton( resources.getString( "view_world" ) );
		
		this.exitButton.addActionListener( createFireViewActionListener( ACTION_TYPE_EXIT ) );
		this.optionsButton.addActionListener( createFireViewActionListener( ACTION_TYPE_OPTIONS ) );
		this.createWorldButton.addActionListener( createFireViewActionListener( ACTION_TYPE_CREATE_WORLD ) );
		this.startGameButton.addActionListener( createFireViewActionListener( ACTION_TYPE_START_GAME ) );
		this.loadGameButton.addActionListener( createFireViewActionListener( ACTION_TYPE_LOAD_GAME ) );
		this.viewWorldButton.addActionListener( createFireViewActionListener( ACTION_TYPE_VIEW_WORLD ) );
		
		JPanel buttons = new JPanel( new GridLayout( 6, 1, 10, 10 ) );
		buttons.add( startGameButton );
		buttons.add( loadGameButton );
		buttons.add( createWorldButton );
		buttons.add( viewWorldButton );
		buttons.add( optionsButton );
		buttons.add( exitButton );
		
		GridBagConstraints c = new GridBagConstraints();
		c.weightx = 1;
		c.weighty = 1;
		c.anchor = GridBagConstraints.CENTER;
		this.component.add( buttons, c );
	}
	
	public void destroy() {
		this.component = null;
		this.exitButton = null;
		this.optionsButton = null;
		this.createWorldButton = null;
		this.startGameButton = null;
		this.loadGameButton = null;
	}
	
	public JComponent getComponent() {
		return this.component;
	}
	
}
